1

00:00:00,475  -->  00:00:05,382
In the previous video, we already install
netmiko on ubuntu server.

2

00:00:05,936  -->  00:00:12,241
Next in this video, we are going to learn
how to do network automation using netmiko.

3

00:00:12,944  -->  00:00:15,186
Let’s see on the documentation.

4

00:00:15,904  -->  00:00:21,160
First, we need to import connect handler function
from netmiko.

5

00:00:21,833  -->  00:00:26,781
The script is From netmiko import connect
handler.

6

00:00:27,230  -->  00:00:33,180
And then here we need to create a dictionary
to shave the router information.

7

00:00:33,659  -->  00:00:42,719
You can use anything for the variable name,
in this example, the variable name is cisco 881.

8

00:00:43,581  -->  00:00:51,366
Here the device type is cisco ios, this is
means that we are going to do network automation

9

00:00:51,366  -->  00:00:53,390
on cisco devices.

10

00:00:54,243  -->  00:01:01,868
If we want to do network automation on other
vendors, we can click on this ssh_dispatcher

11

00:01:02,033  -->  00:01:04,275
to see the other device type.

12

00:01:05,442  -->  00:01:16,226
In the ssh dispatcher, we can see in the CLASS_MAPPER
section, let’s just copy this, go to ssh

13

00:01:16,226  -->  00:01:24,278
dispatcher and then ctrl f to find, paste
it here.

14

00:01:25,000  -->  00:01:29,286
Okay here we can see many device type that
we can use.

15

00:01:30,000  -->  00:01:39,173
For example, if we want to do network automation
on aruba devices, so the device type is aruba_os.

16

00:01:41,986  -->  00:01:46,690
This is that we are use, which is cisco_ios.

17

00:01:47,468  -->  00:01:54,171
Or if you want to do network automation on
cisco nexus series, so the device type will

18

00:01:54,171  -->  00:01:57,208
be cisco_nxos.

19

00:01:58,180  -->  00:02:05,760
If You want to remote cisco ASA Firewall,
So the device type will be cisco_asa

20

00:02:09,426  -->  00:02:24,125
Here we also have juniper, mikrotik, linux,
and others, we have so many choices here.

21

00:02:25,068  -->  00:02:31,760
Okay let’s back to the documentation, here
we need to define host, this is the ip address

22

00:02:31,760  -->  00:02:39,282
of the router, username, this is the username
to remote the router using ssh,

23

00:02:39,506  -->  00:02:41,405
and this is the password.

24

00:02:42,093  -->  00:02:50,839
We also can define the port of ssh, but this
is optional, we only need to define this parameter

25

00:02:50,839  -->  00:02:55,184
if we change the default ssh port on the cisco
router.

26

00:02:56,411  -->  00:03:04,272
Here we also can define enable secret, for
now, the user is in privilege 15,

27

00:03:05,000  -->  00:03:12,759
so when we login using that user, we are in the privilege
mode directly, so we don’t need to define

28

00:03:12,759  -->  00:03:15,212
enable secret parameter here.

29

00:03:16,245  -->  00:03:23,439
After defining the dictionary about the router,
next, we can connect to the router,

30

00:03:24,052  -->  00:03:30,608
this is very simple, we just need to call ConnectHandler
function from netmiko.

31

00:03:31,311  -->  00:03:38,526
And then the argument is the dictionary that
we have created, we need to use stars (*) two

32

00:03:38,526  -->  00:03:42,898
time like this if the argument is a dictionary.

33

00:03:43,915  -->  00:03:46,976
After that, we can send the cisco command.

34

00:03:47,499  -->  00:03:56,393
Let’s say we want to check the cisco interface,
so we can send command show ip interface brief.

35

00:03:57,245  -->  00:03:59,845
And then we can print the output.

36

00:04:00,686  -->  00:04:03,875
Okay, this is more simple than paramiko right?

37

00:04:04,429  -->  00:04:07,999
Let’s try to write the netmiko script on
sublime.

38

00:04:09,001  -->  00:04:14,847
Let’s create new folder, let’s say the
name is lab-netmiko.

39

00:04:17,001  -->  00:04:27,702
And then here inside lab_netmiko, let’s
create new file, let’s say the name is netmiko_basic.py.

40

00:04:36,051  -->  00:04:43,591
Now let’s try to write the netmiko script,
first, let’s import connect handler function

41

00:04:43,591  -->  00:04:45,260
from netmiko.

42

00:04:45,829  -->  00:04:50,727
The script is From netmiko import connect
handler.

43

00:04:55,186  -->  00:05:00,801
Now let’s create a dictionary to save an
information about the router.

44

00:05:01,594  -->  00:05:08,748
We will try to automate router 1 first, so
let’s say the variable name is router 1,

45

00:05:11,666  -->  00:05:14,627
the device type is cisco ios,

46

00:05:18,203  -->  00:05:28,658
the host is the ip address of router 1, which
is 10.10.10.1, the username is cisco,

47

00:05:30,244  -->  00:05:33,528
and the password is also cisco.

48

00:05:34,186  -->  00:05:40,936
We don’t need to define port and secret
for now, because the ssh port on router 1 is

49

00:05:40,936  -->  00:05:48,216
default, which is 22, and our user is already
in the privilege 15.

50

00:05:52,391  -->  00:06:03,159
Now let’s connect to the router, net_connect,
this is just a variable, so you can use anything here,

51

00:06:03,563  -->  00:06:12,925
let’s say we use conn, and then connect
handler, and the dictionary name, which is r1.

52

00:06:15,716  -->  00:06:22,675
After connect to the router, we can send the
cisco command, let’s try to see the interface,

53

00:06:23,094  -->  00:06:29,876
output, conn, this is the variable that we
already defined before.

54

00:06:31,521  -->  00:06:37,452
And then send_command show ip interface brief,

55

00:06:39,352  -->  00:06:42,029
last, let’s print the output.

56

00:06:45,000  -->  00:06:46,820
Okay we have done here.

57

00:06:47,374  -->  00:07:01,475
Save, let’s go to ubuntu server, ls, here
we can see that now we have lab_netmiko,

58

00:07:01,864  -->  00:07:15,923
let’s cd to lab_netmiko, ls, here we can see that
we have netmiko_basic.py. let’s execute this.

59

00:07:18,541  -->  00:07:23,395
Here we can see that we are success to print
the interface of router1,

60

00:07:24,039  -->  00:07:29,631
But there is no description about the router,
let’s modify the script.

61

00:07:30,364  -->  00:07:37,928
Before print the output, let’s print the
router ip address, so here print interface

62

00:07:38,257  -->  00:07:48,775
for router, we can use f string here, and
then here we can define the dictionary name,

63

00:07:49,015  -->  00:07:54,756
which is r1 and let’s access the host key.

64

00:07:57,238  -->  00:08:04,537
Oh sorry, here we already use doble quote,
so here we must use single quote.

65

00:08:08,637  -->  00:08:09,399
Save,

66

00:08:10,970  -->  00:08:15,731
Let’s back to the ubuntu server, execute
the script again.

67

00:08:17,557  -->  00:08:27,283
Okay here we have description, interface for
router 10.10.10.1, and this is the interfaces.

68

00:08:28,091  -->  00:08:31,034
Okay I think enough for this video

69

00:08:31,109  -->  00:08:34,785
Thankyou for watching and see you on the next video.
